<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2024-03-25 15:51:35
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-06-21 15:49:16
-->
<template>
  <aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig" :operateFormate="onOperateFormate">
    <template v-slot:pageName>
      <h3 style="margin-right: 10px;">{{ baseConfig.pageName }}</h3>
    </template>
  </aplid-base-crud>
  <H4>当前已选择委托单位：</H4>
  <div class="" style="margin-top: 20px;">
    <el-tag style="margin:5px;" v-for="tag in tags" :key="tag.id" closable :type="tag.type" @close="handleClose(tag)">
      {{ tag.bindOrgName }}
    </el-tag>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { baseConfig } from './config'
import apiMod from '@/apiMod'
import { ElMessage } from 'element-plus'

const props = defineProps({
  nowRowData: {
    type: Object,
    default: () => { }
  }
})
const tags = ref([])
tags.value = props.nowRowData.omProjectCooperatePOList?.filter(obj => obj.bindType == 2)
const onOperateFormate = (data, type) => {
  return new Promise((resolve, reject) => {
    if (type == 'add') {
      let parameter = {
        projectId: props.nowRowData.id,
        projectName: props.nowRowData.projectName,
        projectStatus: props.nowRowData.projectStatus,
        belongProject: props.nowRowData.belongProject,
        bindCreditCode: data.creditCode,
        bindOrgId: data.id,
        bindOrgName: data.providerName,
        bindType: 2,
      }
      apiMod.view_omProjectCooperate_add(parameter).then((res) => {
        //刷新tab
        apiMod.view_omProjectManagement_page({  id: props.nowRowData.id }).then((res) => {
          if(res.data.records.length ==0) return
          tags.value = res.data.records[0].omProjectCooperatePOList?.filter(obj => obj.bindType == 2)
        })
        ElMessage({
          message: res.data,
          type: 'success',
        })
      })
    } else {
      resolve(data)
    }
  })
}

const handleClose = (tag) => {
  apiMod.view_omProjectCooperate_del([tag.id]).then((res) => {
    //刷新tab
    apiMod.view_omProjectManagement_page({ id: props.nowRowData.id }).then((res) => {
      if(res.data.records.length ==0) return
      tags.value = res.data.records[0].omProjectCooperatePOList?.filter(obj => obj.bindType == 2)
    })
    ElMessage({
      message: res.data,
      type: 'success',
    })
  })
}


</script>

<style lang="scss" scoped></style>